package cn.tedu.lbs.stock.web.rpc;

import cn.tedu.lbs.stock.api.StockApi;
import cn.tedu.lbs.stock.web.service.StockService;
import com.tarena.lbs.pojo.stock.param.CouponStockParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@DubboService
@Component
@Slf4j
public class StockApiImpl implements StockApi {
    @Autowired
    private StockService stockService;
    @Override
    public boolean initCouponStock(CouponStockParam param) {
        boolean result=false;
        try{
            result=stockService.initStock(param);
        }catch (Exception e){
            log.error("初始化优惠券库存异常",e);
        }
        return result;
    }

    @Override
    public Integer getCouponStock(Integer couponId) {
        Integer num=0;
        try{
            num=stockService.getStock(couponId);
        }catch (Exception e){
            log.error("获取优惠券库存异常",e);
        }
        return num;
    }

    @Override
    public boolean updateCouponStock(Integer couponId, Integer num) {
        boolean result=false;
        try{
            result=stockService.reduceStock(couponId,num);
        }catch (Exception e){
            log.error("执行减库存失败",e);
        }
        return result;
    }
}
